﻿
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- saved from url=(0014)about:internet -->
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:mssdk="winsdk" xmlns:script="urn:script" xmlns:build="urn:build" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="Description" content="Source Code Debugging in WinDbg"/>
<meta name="MSHAttr" content="PreferredSiteName:MSDN"/>
<meta name="MSHAttr" content="PreferredLib:/library/windows/hardware"/>
<title>Source Code Debugging in WinDbg</title>

<meta name="MS-HAID" content="r36_gui_1_ea5c9fec-a311-4ddc-8418-23737796865f.xml"/>


<link rel="STYLESHEET" type="text/css" HREF="../common/backsdk4.css"/>





<style>
html,div { margin: 0; padding: 0;}

body {
	padding: 0px;
	margin: 0px;
	overflow: auto;
	height: 100%;
}

#winchm_template_button{
	float: right;
	width: 93px;
	top: 7px;
	position: relative;
	text-align: right;
	right: 5px;
	height: auto;
}

#winchm_template_top{
	padding: 0px;
	margin: 0px;
	border-bottom: 1px solid #9B9B9B;
	background-color: #B1CEFE;
}

#winchm_template_navigation{
	margin: 0px;
	padding-top: 7px;
	padding-left: 7px;
	padding-bottom: 3px;
	padding-right: 0px;
	font-size: 8.5pt;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: normal;
	color: #585858;
}

#winchm_template_title{
	margin: 0px;
	padding-top: 4px;
	padding-left: 7px;
	padding-bottom: 7px;
	padding-right: 0px;
	font-size: 18px; 
	font-family: Verdana, Geneva, sans-serif;
	color: #363636;
}

#winchm_template_content{
	margin-top: 20px;
	margin-left: 15px;
	margin-bottom: 20px;
	margin-right: 15px;
	width: auto  !important;
	width: 100%;
}

#winchm_template_footer{
	border-width: 1px;
	border-color: #B1CEFE;
	border-top-style: solid;
	margin-top: 15px;
	margin-left: 15px;
	margin-bottom: 20px;
	margin-right: 15px;
	padding-top: 7px;
	padding-left: 0px;
	padding-bottom: 0px;
	padding-right: 0px;
	font-family: arial, helvetica, sans-serif;
	font-size: 8.5pt;
	color: #696969;
	width: auto;
	text-align: left;
}


#winchm_template_container{
	margin: 0px;
	padding: 0px;
	position: static;
	padding-bottom: 3px;
	overflow: auto;
	background-color: #FFFFFF;
}


@media print
{
#winchm_template_container{
	position: static;	
	margin: 0px;
	padding: 5px;
	
	width: auto;
	height: auto;
	overflow: auto;
}
#winchm_template_button{
visibility:hidden;
}
}

#winchm_template_navigation A:link	{text-decoration: none; color:#004080}
#winchm_template_navigation A:visited  {text-decoration: none; color: #004080}
#winchm_template_navigation A:active {text-decoration: none; color: #004080 }
#winchm_template_navigation A:hover {text-decoration: none;color: #0080FF}

A:link	{text-decoration: underline; color:#0033CC}
A:visited  {text-decoration: underline; color: #0033CC}
A:active {text-decoration: underline; color: #0033CC }
A:hover {text-decoration: underline;color: #FF0000;}
</style>
<script type="text/javascript">
function isMobile(){
Agent = window.navigator.userAgent;
if (Agent.indexOf("iPhone")>=1 || Agent.indexOf("iPad")>=1 || Agent.indexOf("iPod")>=1 || Agent.indexOf("Android")>=1){
return true;
}else{
return false;	
}

}
function d_onresize(){
if (window.navigator.userAgent.indexOf("MSIE")>=1){
document.getElementById('winchm_template_container').style.pixelWidth = document.body.offsetWidth - 3;
document.getElementById('winchm_template_container').style.pixelHeight = document.body.offsetHeight - document.getElementById('winchm_template_top').offsetHeight - 4;
}
document.getElementById('winchm_template_container').style.top = document.getElementById('winchm_template_top').offsetHeight + 'px';
}

function d_onbeforeprint(){
document.getElementById('winchm_template_container').style.width = 'auto';
document.getElementById('winchm_template_container').style.height = 'auto';
}

function d_onafterprint(){
d_onresize();
}

if(!isMobile()){

window.onload = d_onresize;
window.onresize = d_onresize;
window.onbeforeprint = d_onbeforeprint;
window.onafterprint = d_onafterprint;

document.write("<style>\n");
document.write("body {overflow: hidden;}\n");
document.write("#winchm_template_container {position: absolute;overflow: auto;top : 0px;right: 0px;bottom: 0px;left: 0px;}\n");
document.write("</style>\n");
}

</script>
</head>
<body><script language="JavaScript" type="text/JavaScript">
function syn(){
if(parent.nav.tree){
 if(parent.nav.tree.loaded){
  parent.nav.tree.selectNode(1228);
 }else{
  setTimeout("syn()",500);
}
  }else{
  setTimeout("syn()",500);
  }}
if(parent!=self){
  setTimeout("syn()",100);
}else{
  parent.location.href = "../../index.htm?page=debugger/source_window.htm";
}
originalOnload = window.onload;
if(originalOnload==null){
window.onload = function(){parent.contentLoaded = true;};
}else{
window.onload = function(){originalOnload();parent.contentLoaded = true;};
}
</script> 


<div id="winchm_template_top">
	<div id="winchm_template_button"><A href="disassembly_window.htm" title="Previous topic"><img id="winchm_template_prev" alt="Previous topic" src="../template2/btn_prev_n.gif" border="0"></a><A href="memory_window.htm" title="Next topic"><img id="winchm_template_next" alt="Next topic" src="../template2/btn_next_n.gif" border="0"></a></div>
	<div id="winchm_template_navigation">Help &gt; 
<A href="introduction6.htm">Debugging Tools for Windows (WinDbg, KD, CDB, NTSD)</A> &gt; <A href="debugger_operation_win8.htm">Debugger Operation</A> &gt; <A href="debugging_using_windbg.htm">Debugging Using WinDbg</A> &gt; </div>
	<div id="winchm_template_title">Source Code Debugging in WinDbg</div>
</div>
<div id="winchm_template_container">
	<div id="winchm_template_content"><div id="mainSection"><h2><a id="ddk_source_path_dbg"></a><a id="DDK_SOURCE_PATH_DBG"></a>Source Path</h2>
<p>The source path specifies the directories where the C and C++ source files are located. For more information about viewing source code in the debugger, see <a href="#Bookmark146">Source Code</a>.</p>
<div class="alert"><b>Note</b>    If you are connected to a corporate network, the most efficient way to access source files is to use a source server. You can use a source server by using the srv* string within your source path. For more information about source servers, see <a href="#Bookmark148">Using a Source Server</a>. </div>
<div> </div>
<p>To control the source path in WinDbg, do one of the following:</p>
<ul>
<li>
<p>
         Choose <b>Source File Path</b> from the <b>File</b> menu or press CTRL+P.</p>
</li>
<li>
<p>Use the <a href="#Bookmark2188"><b>.srcpath (Set Source Path)</b></a> command. If you are using a source server, <a href="#Bookmark2186"><b>.srcfix (Use Source Server)</b></a> is slightly easier.</p>
</li>
<li>
<p>
         Use the <a href="#Bookmark2188"><b>.lsrcpath (Set Local Source Path)</b></a> command. If you are using a source server, <a href="#Bookmark2186"><b>.lsrcfix (Use Local Source Server)</b></a> is slightly easier.</p>
</li>
<li>
<p>When you start the debugger, use the <b>-srcpath</b> or <b>-lsrcpath</b> command-line option. See <a href="#Bookmark1905"><b>WinDbg Command-Line Options</b></a>.</p>
</li>
<li>
<p>Before you start the debugger, set the _NT_SOURCE_PATH <a href="#Bookmark1912">environment variable</a>.</p>
</li>
</ul>
<h2><a id="Opening_and_Closing_Source_Files"></a><a id="opening_and_closing_source_files"></a><a id="OPENING_AND_CLOSING_SOURCE_FILES"></a>Opening and Closing Source Files</h2>
<p>To open or close a source file directly, do one of the following:</p>
<ul>
<li>
<p>Choose <b>Open Source File</b> from the <b>File</b> menu, or press CTRL+O. You can also use the <b>Open source file</b> button (<img src="images/tbopen.png" alt="Screen shot of the Open Source File button"/>) on the toolbar.
</p>
<div class="alert"><b>Note</b>  When you use the menu or the toolbar button to open a source file, the path of that file is automatically appended to the source path.

</div>
<div> </div>
</li>
<li>Choose <b>Close Current Window</b> from the <b>File</b> menu.</li>
<li>Click the <b>Close</b> button in the corner of the Source window.</li>
<li>Choose <b>Recent Files</b> from the <b>File</b> menu to open one of the four source files that you most recently opened in WinDbg.
</li>
<li>Enter the <a href="#Bookmark2149"><b>.open (Open Source File)</b></a> command.
</li>
<li>Enter the <a href="#Bookmark2012"><b>lsf (Load or Unload Source File)</b></a> command.</li>
</ul>
<h2><a id="ddk_source_windows_dbg"></a><a id="DDK_SOURCE_WINDOWS_DBG"></a></h2>
<p>In WinDbg, the Source window displays source files that have been loaded into the debugger. </p>
<h3><a id="opening_the_source_window"></a><a id="OPENING_THE_SOURCE_WINDOW"></a>Opening the Source Window</h3>
<p>The debugger opens a source window when it loads a new source file. To restore or switch to an open Source window, go to the <b>Window</b> menu and choose from the list of windows at the bottom of the menu.</p>
<p>The following screen shot  shows an example of a Source window.</p><img src="images/window-source.png" alt="Screen shot of the Source window, displaying a source file that has been loaded into the debugger"/><p>Each source file resides in its own Source window. The title of each Source window is the full path of the source file.</p>
<h3><a id="using_the_source_window"></a><a id="USING_THE_SOURCE_WINDOW"></a>Using the Source Window</h3>
<p>Each Source window displays the text of one source file. You cannot edit a source file in the debugger. For more information about changing the font and tab settings, see <a href="#Bookmark1282">Changing Text Properties</a>.</p>
<p>Each Source window has a shortcut menu with additional commands. To access the menu, right-click the title bar or click the icon that appears near the upper-right corner of the window (<img src="images/window-source-icon.PNG" alt="Screen shot of the button that displays the Source window toolbar shortcut menu"/>). The following list describes some of the menu commands:</p>
<ul>
<li>
<p><b>Set instruction pointer to current line</b> changes the value of the instruction pointer to the instruction that corresponds to the current line. This command is equivalent to using the <a href="#Bookmark2886">Edit | Set Current Instruction</a> command or pressing CTRL+SHIFT+I.</p>
</li>
<li><b>Edit this file</b> opens the source file in a text editor. The editor is determined by the WinDiff editor registry information or by the value of the WINDBG_INVOKE_EDITOR environment variable. For example, consider the case when the value of WINDBG_INVOKE_EDITOR is the following.<div class="code"><span codelanguage=""><table>
<tr>
<th></th>
</tr>
<tr>
<td>
<pre>c:\my\path\myeditor.exe -file %f -line %l</pre>
</td>
</tr>
</table></span></div>
<p>In this case, Myeditor.exe will open to the one-based line number of the current source file. The %l option indicates that line numbers should be read as one-based, while %f indicates that the current source file should be used. Other substitution possibilities include %L, which indicates that line numbers are zero-based, and %p, which can also indicate that the current source file should be used.  </p>
</li>
<li>
<p>
       <b>Evaluate selection</b> evaluates the currently selected text by using the C++ expression evaluator. The result appears in the <a href="#Bookmark1223">Debugger Command window</a>. If the selected text includes more than one line, a syntax error results. This command is equivalent to using the <a href="#Bookmark2879">Edit | Evaluate Selection</a> command, pressing CTRL+SHIFT+V, or using the  <a href="#Bookmark1956"><b>?? (Evaluate C++ Expression)</b></a> command with the selected text as its argument.</p>
</li>
<li>
<p><b>
       Display selected type</b> displays the data type of the selected object. This display appears in the Debugger Command window. If the selected text includes more than a single object, a syntax error or other irregular results might be displayed. This command is equivalent to using the <a href="#Bookmark2880">Edit | Display Selected Type</a> command or pressing CTRL+SHIFT+Y.</p>
</li>
<li>
<p>
        
       <b>Open memory window for selection</b> opens a new docked Memory window that displays memory starting at the address of the selected expression.</p>
</li>
<li>
<p>
        
       <b>Add selection to Watch window</b> appends the selected source token to the Watch window.</p>
</li>
<li>
<p><b>
       Disassemble at current line</b> causes the instruction that corresponds to the current line to appear in the <a href="#Bookmark1227">Disassembly window</a>. The selected line is highlighted in the Source window and in the Disassembly window, but this command affects only the display&#8212;the instruction pointer is not changed. If the Disassembly window is closed when this command is clicked, it is opened.</p>
</li>
<li>
<p><b>
       Select source language</b> displays a list of programming languages. Select the programming language that you used to generate the source file, and then click <b>OK</b> to enable basic syntax highlighting for the current Source window. Select <b>&lt;None&gt;</b> to disable syntax highlighting for the current Source window.</p>
</li>
</ul>
<h3><a id="source_window_colors_and_hover_evaluation"></a><a id="SOURCE_WINDOW_COLORS_AND_HOVER_EVALUATION"></a>Source Window Colors and Hover Evaluation</h3>
<p>If the debugger recognizes the source file name extension, the Source window displays certain syntax elements in color. To turn off or change the colors, do the following:</p>
<ul>
<li>
<p>To turn the syntax colors off in a single window, open the Source window's shortcut menu, click <b>Select source language</b>, and then click <b>&lt;None&gt;</b>. </p>
</li>
<li>
<p>To turn the syntax colors off for all Source windows, choose <b>Options</b> from the <b>View</b> menu. Then clear the <b>Parse Source Languages</b> check box.</p>
</li>
<li>
<p>To change the syntax colors, choose <b>Options</b> from the <b>View</b> menu. Then, in the <b>Colors</b> area, select a syntax element and click the <b>Change</b> button to change the color.</p>
</li>
<li>
<p>The parsing method that is used for the highlighting is determined by the programming language that is associated with the file extension for the source file. To change the programming language that is associated with a specific file extension, use the <a href="#Bookmark2906">File Extensions for Source Languages dialog box</a>. To open this dialog box, choose <b>Source language file extensions</b> from the <b>View</b> menu.</p>
</li>
</ul>
<p>The line that represents the current program counter is highlighted. Lines at which breakpoints are set are highlighted as well.</p>
<p>If you select a Source window and then use the mouse to hover over a symbol in that window, the symbol will be evaluated. The evaluation is the same as that produced by the <a href="#Bookmark1991"><b>dt (Display Type)</b></a> command. To deactivate this evaluation, choose <b>Options</b> from the <b>View</b> menu. Then clear the <b>Evaluate on hover</b> check box.</p>
<h3><a id="additional_information"></a><a id="ADDITIONAL_INFORMATION"></a>Additional Information</h3>
<p>For more information about source debugging and related commands, see <a href="#Bookmark1371">Debugging in Source Mode</a>.</p></div></div>	
	<div id="winchm_template_footer">Copyright &copy; 2019. All rights 
reserved. (To change the copyright info, just edit it in template.)</div>
</div>

</body>
</html>
